package com.ruoyi.user.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.user.domain.MyRepair;
import com.ruoyi.user.service.IMyRepairService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 维修预约Controller
 * 
 * @author xjl
 * @date 2024-09-13
 */
@RestController
@RequestMapping("/myRepair")
public class MyRepairController extends BaseController
{
    @Autowired
    private IMyRepairService myRepairService;

    /**
     * 查询维修预约列表
     */
    @RequiresPermissions("system:myRepair:list")
    @GetMapping("/list")
    public TableDataInfo list(MyRepair myRepair)
    {
        startPage();
        List<MyRepair> list = myRepairService.selectmyRepairList(myRepair);
        return getDataTable(list);
    }

    /**
     * 导出维修预约列表
     */
    @RequiresPermissions("system:myRepair:export")
    @Log(title = "维修预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MyRepair myRepair)
    {
        List<MyRepair> list = myRepairService.selectmyRepairList(myRepair);
        ExcelUtil<MyRepair> util = new ExcelUtil<MyRepair>(MyRepair.class);
        util.exportExcel(response, list, "维修预约数据");
    }

    /**
     * 获取维修预约详细信息
     */
    @RequiresPermissions("system:myRepair:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(myRepairService.selectmyRepairById(id));
    }

    /**
     * 新增维修预约
     */
//    @RequiresPermissions("system:myRepair:add")
//    @Log(title = "维修预约", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody MyRepair myRepair)
//    {
//        return toAjax(myRepairService.insertmyRepair(myRepair));
//    }



    /**
     * 新增维修预约
     */
    @RequiresPermissions("system:myRepair:add")
    @Log(title = "维修预约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyRepair myRepair)
    {
        MyRepair newRepair = myRepairService.insertmyRepair(myRepair);

        if (newRepair != null) {
            // 返回新插入的维修预约信息
            return AjaxResult.success(newRepair);
        } else {
            return AjaxResult.error("插入维修预约失败");
        }
    }

    /**
     * 修改维修预约
     */
    @RequiresPermissions("system:myRepair:edit")
    @Log(title = "维修预约", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyRepair myRepair)
    {
        return toAjax(myRepairService.updatemyRepair(myRepair));
    }

    /**
     * 删除维修预约
     */
    @RequiresPermissions("system:myRepair:remove")
    @Log(title = "维修预约", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(myRepairService.deletemyRepairByIds(ids));
    }





    /*根据当前详情页订单id，修改订单状态为已取消*/
    @PutMapping("/updateStatus")
    public AjaxResult updateStatus(@RequestBody MyRepair myRepair){
        return toAjax(myRepairService.cancelRepair(myRepair));
    }

    }

